﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.workPlan
{
    public partial class ListWorkPlanEva : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                    int user_depid = 0;
                    if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                    {
                        user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                    }

                    Bind(roles_id, user_depid, user_id);

                }

            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_look")
            {
                Response.Redirect("WorkPlanLook.aspx?workplan_id=" + e.CommandArgument);
            }
            if (e.CommandName == "lbn_check")
            {
                Response.Redirect("WorkPlanEva.aspx?workplan_id=" + e.CommandArgument);
            }
            if (e.CommandName == "lbn_up")
            {
                Response.Redirect("EmpSubmit.aspx?workplan_id=" + e.CommandArgument);
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并设置新的背景色
                e.Row.Attributes.Add("onmouseover", "onmouseroverop(this)");
                //当鼠标离开的时候 将背景颜色恢复成之前的颜色
                e.Row.Attributes.Add("onmouseout", "onmouseroutop(this)");
                //单击行改变行背景颜色
                e.Row.Attributes.Add("onclick", "ItemOver(this)");


                LinkButton lbn_check = (LinkButton)e.Row.FindControl("lbn_check");
                LinkButton lbn_look = (LinkButton)e.Row.FindControl("lbn_look");

                Label lbl_checkstep = (Label)e.Row.FindControl("lbl_checkstep");

                if (lbl_checkstep.Text == "班长评价完成" || lbl_checkstep.Text == "绩效专责评价完成" || lbl_checkstep.Text == "部门经理评价完成")
                {
                    lbn_check.Visible = false;
                }
                else
                {
                    lbn_check.Visible = true;
                }

                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());

                    if (roles_id == 1024)
                    {
                        //班长
                        if (lbl_checkstep.Text == "班长评价完成" || lbl_checkstep.Text == "绩效专责评价完成" || lbl_checkstep.Text == "部门经理评价完成")
                        {
                            lbn_check.Visible = false;
                        }
                        else
                        {
                            lbn_check.Visible = true;
                        }
                    }
                    if (roles_id == 1025)
                    {
                        //绩效专责
                        if (lbl_checkstep.Text == "班长评价完成" || lbl_checkstep.Text == "绩效专责评价完成" || lbl_checkstep.Text == "部门经理评价完成")
                        {
                            lbn_check.Visible = false;
                        }
                        else
                        {
                            lbn_check.Visible = true;
                        }

                    }
                    if (roles_id == 1026)
                    {
                        //部门经理

                        if (lbl_checkstep.Text == "部门经理评价完成")
                        {
                            lbn_check.Visible = false;
                        }
                        else
                        {
                            lbn_check.Visible = true;
                        }
                    }
                }
            }

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                int user_depid = 0;
                if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                {
                    user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                }

                Bind(roles_id, user_depid, user_id);

            }
        }

        private void Bind(int roles_id, int user_depid, int user_id)
        {
            Maticsoft.BLL.workplan wm = new Maticsoft.BLL.workplan();
            DataSet ds = null;

            
            if (roles_id == 1024)
            {
                //班长
                ds = wm.GetListByUserWorkPlan(" (check_step='班长评价' or check_step='班长评价完成')  and user_depid= " + user_depid);

            }
            if (roles_id == 1025)
            {
                //绩效专责
                ds = wm.GetListByUserWorkPlan(" (check_step='绩效专责评价' or check_step='绩效专责评价完成' or check_step='部门经理评价完成') and user_depid= " + user_depid);

            }
            if (roles_id == 1026)
            {
                //部门经理
                ds = wm.GetListByUserWorkPlan(" (check_step='绩效专责评价完成' or check_step='部门经理评价完成') and user_depid= " + user_depid);
            }

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

        }
    }
}
